package com.ponchware.classes
{
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLRequest;
	
	public class SoundManager
	{
		private static var channels:Object = new Object();
		private static var bgMusic:SoundChannel;
		
		public function SoundManager()
		{
		}
		
		public static function playSound(mp3:Class, start:Number = 0, looping:Boolean = false):void
		{
			var sound:Sound = new mp3();
			var channel:SoundChannel = sound.play(start, 0);
			if (looping)
				channels[mp3] = channel;
		}
		
		public static function stopSound(mp3:Class):void
		{
			var channel:SoundChannel = channels[mp3];
			if (channel)
				channel.stop();
			delete channels[mp3];
		}
		
		public static function playMusic(filename:String):void
		{
			if (bgMusic)
			{
				bgMusic.stop();
				bgMusic = null;
			}
			
			var req:URLRequest = new URLRequest("com/ponchware/music/" + filename);
			trace(req.url);
			var music:Sound = new Sound(req);
			bgMusic = music.play();
		}
		
		public static function stopMusic():void
		{
			if (bgMusic)
			{
				bgMusic.stop();
				bgMusic = null;
			}
		}

	}
}